﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;


namespace MessageBroadcast
{
    internal class Program
    {
        static void Main()
        {
            Project.CreateProj("1000秒可控核聚变研究项目",ProjTypeConst.Sci);

            foreach (var item in System.Configuration.ConfigurationSettings.AppSettings.AllKeys)
            {

            }
        }
    }

    public class Project
    {
        public string ProjCode { get; set; }
        public string ProjName { get; set; }
        public string ProjType { get; set; }

        protected Project(string name, string type)
        {
            ProjCode = Guid.NewGuid().ToString().Split('-')[0];
            this.ProjName = name;
            this.ProjType = type;
        }

        public static void CreateProj(string name, string type)
        {
            Console.WriteLine($"正在创建{ProjTypeConst.GetName(type)}项目{name}... ...");

            var proj = new Project(name, type);

            Console.WriteLine($"项目{proj.ProjCode}-{proj.ProjName}保存成功！");

            var examples = Assembly.GetAssembly(typeof(IReceiveMessage)).GetTypes().ToList().Where(t=>t.GetInterfaces().Contains(typeof(IReceiveMessage))).ToList();

            examples.ForEach(exampleItem =>
            {
                var instance = Activator.CreateInstance(exampleItem) as IReceiveMessage;
                instance.Receive(proj);
            });
        }
    }

    public static class ProjTypeConst
    {
        /// <summary>
        /// 科研类
        /// </summary>
        public const string Sci = "Sci";

        /// <summary>
        /// 财务类
        /// </summary>
        public const string Fin = "Fin";

        /// <summary>
        /// 基建类
        /// </summary>
        public const string Ifs = "Ifs";

        /// <summary>
        /// 教育类
        /// </summary>
        public const string Edu = "Edu";

        private static readonly Dictionary<string, string> _Names = new Dictionary<string, string>
        {
           { Sci, "科研类" },
           { Fin, "财务类" },
           { Ifs, "基建类" },
           { Edu, "教育类" },
        };

        /// <summary>
        /// 常量列表
        /// </summary>
        /// <returns></returns>
        public static string[] GetAllKeys()
        {
            return _Names.Keys.ToArray();
        }

        /// <summary>
        /// 获取名称
        /// </summary>
        /// <returns></returns>
        public static string GetName(string key)
        {
            return _Names.ContainsKey(key) ? _Names[key] : string.Empty;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        public static List<KeyValuePair<string, string>> GetAllList()
        {
            return _Names.ToList();
        }

    }

}
